using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Dogfight2008
{
  public partial class TweakDialog : Form
  {
    TweakConfig config;

    public TweakDialog(TweakConfig config)
    {
      InitializeComponent();

      this.config = config;
      FillDataView();
    }

    private void FillDataView()
    {
      foreach (string property in config.GetProperties())
        dataGridView1.Rows.Add(property, config.GetPropertyValue(property, 0));
    }

    private void btnOK_Click(object sender, EventArgs e)
    {
      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
        string property = (string)row.Cells[0].Value;
        try
        {
          double value = double.Parse(row.Cells[1].Value as string);
          config.SetPropertyValue(property, value);
        }
        catch { }
      }
    }

    private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
      DataGridViewCell cell = dataGridView1[e.ColumnIndex, e.RowIndex];
      string value = cell.Value as string;
      try
      {
        double.Parse(value);
      }
      catch
      {
        cell.Value = "0";
      }
    }
  }
}